<template>
	<view class="redpack">
		<view class="white_bg">

		</view>
		<view class="coins">
			<text>可用{{names.coin}}</text>
			<view class="count">{{userinfo.user_virtual_coin | toFixedZero}}</view>
			<view class="rule_text" @click="goPage('/pagesA/my/rules/ruleDetail?type=18')">
				兑换规则
			</view>
		</view>

		<view class="lists">
			<view class="single" v-for="(item,index) in infoList" :key="index">
				<view class="info">
					<text>{{item.type}}</text>
					<text class="create_time">{{item.create_date}}</text>
				</view>
				<view class="detail">
					<text class="title">{{item.remark}}</text>
					<text class="price">{{item.amount | toFixedZero}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		name_config
	} from "@/common/config.js"
	import {
		coins
	} from '@/api/my/my.js';
	import {
		store
	} from "@/store/index.js";
	export default {
		data() {
			return {
				names: name_config,
				coins: 8979,

				infoList: [],
				page: 1, //页码
				size: '10',
				loadStatus: 'loading', //加载样式：more-加载前样式，loading-加载中样式，nomore-没有数据样式
				isLoadMore: false, //是否加载中
				refresh: false, // 下拉刷新标示
			}
		},
		computed: {
			userinfo() {
				return this.$store.state.userinfo;
			},
		},
		onLoad() {
			this.getDataList();
		},
		methods: {
			// 列表
			getDataList() {
				uni.showLoading({
					title: '加载中'
				});
				coins('virtualcoinrecord', {
					page: this.page,
					page_size: this.size,
				}).then(res => {
					let datas = res.data.data;
					this.infoList = this.page == 1 ? datas : this.infoList.concat(datas);
					if (datas.length < this.size) { //小于size数，停止请求
						this.isLoadMore = true;
						this.loadStatus = 'nomore';
					} else {
						this.isLoadMore = false;
					}
					uni.hideLoading();
					if (this.refresh) {
						uni.stopPullDownRefresh();
						this.refresh = false;
					}
				}).catch(error => {
					uni.hideLoading();
					this.isLoadMore = false;
				})
			},
			goPage(url) {
				uni.navigateTo({
					url: url,
				});
			},
			onPullDownRefresh() {
				this.page = 1;
				this.getDataList();
				this.refresh = true;
			},
			onReachBottom() {
				if (!this.isLoadMore) { //此处判断，上锁，防止重复请求
					this.isLoadMore = true;
					this.page++;
					this.getDataList();
				}
			},
		}
	}
</script>

<style>
	page {
		background-color: #EFF0F1;
	}
</style>
<style lang="scss" scoped>
	@mixin bck_img($url) {
		background: url($url) no-repeat;
		background-size: 100% 100%;
	}

	@mixin cards {
		box-sizing: border-box;
		width: 94%;
		height: 328rpx;
		margin: 20rpx 3%;
		background: #FFFFFF;
		border-radius: 24rpx;
	}

	@mixin flexLayout($align, $justy) {
		display: flex;
		align-items: $align;
		justify-content: $justy;
	}

	.white_bg {
		height: 206rpx;
		background-color: #FFFFFF;
	}

	.coins {
		@include cards;
		@include flexLayout(center, center);
		@include bck_img($img-link+'/my/card-bg.png');
		flex-direction: column;
		position: relative;
		top: -206rpx;
		color: #FFFFFF;
		font-size: 24rpx;

		.count {
			font-size: 56rpx;
			margin-top: 10rpx;
		}

		.rule_text {
			width: 126rpx;
			height: 50rpx;
			line-height: 50rpx;
			position: absolute;
			right: 0;
			top: 40rpx;
			color: #F54642;
			background: #FFFFFF;
			border-radius: 200rpx 0rpx 0rpx 200rpx;
			text-align: center;
		}
	}

	.image-1 {
		flex-shrink: 0;
		margin-right: 10px;
		width: 125px;
		height: 75px;
		border-radius: 6px;
		overflow: hidden;
		border: 1px #f5f5f5 solid;
	}

	.lists {
		position: relative;
		top: -206rpx;
		padding: 0 30rpx;
		font-size: 28rpx;
		color: #181818;

		.single {
			border-bottom: 2rpx solid #e7e8e9;
			padding: 26rpx 0;

			.info {
				@include flexLayout(center, space-between);

				.create_time {
					color: #969696;
					font-size: 24rpx;
				}
			}

			.detail {
				@include flexLayout(center, space-between);
				margin-top: 18rpx;

				.title {
					display: inline-block;
					width: 86%;
					color: #5A5A5A;
				}

				.price {
					font-size: 30rpx;
					color: #F54642;
				}
			}
		}
	}
</style>
